"""
2017年3月6日 星期一
版本：  V3.5.1
python 实现线/进程机制
"""
import multiprocessing as mp
import time

def worker(num):
    n = 5
    while n > 0:
        print("The time is {0}".format(time.ctime()))
        time.sleep(num)
        n -= 1

#  worker 函数调用器
def workerCaller():
    p = mp.Process(target=worker, args=(3,))
    p.start()
    print({
        'pid': p.pid,
        'name': p.name,
        'is_alive': p.is_alive()
    })

class processActor(mp.Process):
    def __init__(self,pname):
        mp.Process.__init__(self)
        self.pname = pname

    def worker(self,num):
        n = 5
        while n > 0:
            print(self.pname,"The time is {0}".format(time.ctime()))
            time.sleep(num)
            n -= 1

    def run(self):
        self.worker(3)

def processActorCaller():
    pA = processActor("进程一")
    pA.start()
    pA = processActor("HuiJuan - ")
    pA.start()
if __name__ == '__main__':
    # workerCaller()
    processActorCaller()